<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="./Css/style.css"/>
    <script type="text/javascript" src="./Js/jquery.js"></script>
    <script type="text/javascript" src="./Js/bootstrap.js"></script>
    <script type="text/javascript" src="./Js/ckform.js"></script>
    <script type="text/javascript" src="./Js/common.js"></script>
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/ueditor.all.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="./BDUeditor/lang/zh-cn/zh-cn.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<form action="need/add" method="post">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td class="tableleft">标题</td>
            <td><input type="text" id="title" name="title" value="" style="width: 360px;"/></td>
        </tr>
        <tr>
            <td class="tableleft">紧急状态</td>
            <td>
                <input name="status" type="radio" value="2" checked/> 非常紧急
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input name="status" type="radio" value="1"/> 紧急
            </td>
        </tr>
        <tr>
            <td class="tableleft">选择学校</td>
            <td>
                <select id="schId" name="schoolid">
                    <c:forEach items="${schools}" var="school">
                        <option value="${school.id}">${school.schoolname}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">详细信息</td>
            <td>
                <div>
                    <script type="text/plain" id="info" name="info" style="width:1024px;height:500px;"></script>
                    <%--		    	<textarea rows="5" cols="5"></textarea>--%>
                </div>
            </td>
        </tr>

        <tr>
            <td class="tableleft"></td>
            <td>
                <button type="button" id="submit-button" class="btn btn-primary">保存</button>
                &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
    $("#backid").click(function () {
        window.location.href = "/demand/list";
    })
    var info = UE.getEditor("info", {
        autoFloatEnabled: false//是否保持toolbar位置不懂，默认为true
    });
    $("#submit-button").click(function () {
        var title = $("#title").val();
        var schoolid = $("#schId").val();
        var status = $("input[name='status']:checked").val();
        var param = "title=" + title + "&status=" + status + "&info=" + UE.getEditor("info").getContent() + "&schoolid=" + schoolid+"&operator=${username}";
        $.ajax({
            url: "/demand/add",
            type: "post",
            async: true,
            data: param,
            success: function (res) {
                if (res.success) {
                    alert("添加成功！")
                    window.location.href = "/demand/list";
                } else {
                    alert(res.message);
                }
            }, error: function (e) {
                alert(e)
            }
        });
    });
</script>
</html>